* Load data
use "$data/waterpipe_touse.dta"
local socdem="age3549 age5064 age65above some_college_or_assdegr hs ba_or_more i.inc_group female white"
*local socdem="female age3549 age5064 age65above school_medtier school_hightier inc_med inc_high white"

svyset caseid [pweight=weight]

*-----------------------------------
* Waterpipe Problem: Choice and Payment Plans
/*
Suppose that the water pipe system in your region is deteriorating. Upgrades and repairs seem vital to secure the supply of fresh water to households.
Engineers have determined that either of the following repair plans will work, although the required timing of household contributions is different.
Please let us know which of the following two options you prefer:

Option 1
Year 			2020 2021 2022 2023 2024
Monthly
household
contributions	$50 $50 $50 $50 $50

Option 2
Year 			2020 2021 2022 2023 2024
Monthly
household
contributions 	$20 $20 $20 $95 $95

Order of options was randomized
*/
*-----------------------------------


* Tables 2, A2, and A3
regress wtrppe_constplan patience_ctb_trim_high patience_ctb_trim_high, robust
outreg2 using "$output/Table2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) replace
outreg2 using "$output/TableA2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) replace
outreg2 using "$output/TableA3.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) replace
regress wtrppe_constplan patience_ctb_trim_high riskacceptance_ctb_trim_high `socdem', robust

foreach var in ///
"patience_ctb_trim" ///
"patience_ctb_trim_high" ///
"patience_stated" ///
"patience_stated_high" {

eststo `var': regress wtrppe_constplan `var', robust
outreg2 using "$output/Table2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append

eststo `var'_sd: regress wtrppe_constplan `var' `socdem', robust
outreg2 using "$output/Table2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append

svy: regress wtrppe_constplan `var'
outreg2 using "$output/TableA2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append

svy: regress wtrppe_constplan `var' `socdem'
outreg2 using "$output/TableA2.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append

eststo `var': regress wtrppe_constplan `var' riskacceptance_ctb_trim_high, robust
outreg2 using "$output/TableA3.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append
eststo `var'_sd: regress wtrppe_constplan `var' `socdem' riskacceptance_ctb_trim_high, robust
outreg2 using "$output/TableA3.xls", ctitle("Waterpipe: Constant Plan Chosen" "`var'") excel bdec(3) sdec(3) stats(coef se) append


}
